
#ifndef __VTY_PROXY_AGENT_HPP__
#define __VTY_PROXY_AGENT_HPP__

#include "khan.hpp"
#include "vty.hpp"
#include "vty_ipc_msg.hpp"
#include "vty_agent_session.hpp"

/* FIXME */
class vty_agent_server
{
public:
    vty_agent_server(boost::asio::io_service& io_service, short port):
        _io_service(io_service),
		_port(port), _is_stop(false)
	{}

    void run() {
		_acceptor.reset(
				new tcp_acceptor(_io_service, tcp::endpoint(tcp::v4(), _port)));
		for (;;)
        {
            if (_is_stop) break;
            vty_agent_session_ptr session(
                    new vty_agent_session(_io_service));
            _acceptor->accept(session->socket());
            boost::thread t(boost::bind(&vty_agent_session::run, session));
        }
    }

	void stop() { 
		_is_stop = true; 
		_acceptor->cancel();
		_acceptor->close();
	}


private:
	io_service& _io_service;
    short _port;
    bool _is_stop;
	tcp_acceptor_ptr _acceptor;
};

#endif  /* __VTY_PROXY_AGENT_HPP__ */
